package com.laot.searchManage.controller;

import com.laot.searchManage.utils.UserUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.laot.seacher_master.model.common.BaseResponse;
import org.laot.seacher_master.model.common.ResultUtils;
import org.laot.seacher_master.model.entity.User;
import org.laot.searchManage.service.INoticeBoardService;
import org.laot.searchManage.vo.NoticeBoardVo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


/**
 * 公告栏管理接口
 * @author laoT
 * @date 2024/1/27
 */
@Slf4j
@Api(tags = "公告栏管理接口")
@RestController
@RequestMapping("/noticeBoard")
public class NoticeBoardController {

    @Resource
    private INoticeBoardService noticeBoardService;
    @Resource
    private UserUtils userUtils;

    @GetMapping("/updateContent")
    @ApiOperation("修改公告栏内容")
    public BaseResponse<String> updateContent(String content, HttpServletRequest request){
        //获取用户名
        User user = userUtils.getLoginUser(request);
        noticeBoardService.updateContent(content,user.getUserName());
        return ResultUtils.success("修改成功！");
    }

    @GetMapping("/getContent")
    @ApiOperation("获取公告栏内容")
    public BaseResponse<NoticeBoardVo> getContent(){
        NoticeBoardVo noticeBoardVo = noticeBoardService.getContent();
        return ResultUtils.success(noticeBoardVo);
    }

    @GetMapping("/updateStatus")
    @ApiOperation("发布或取消公告栏")
    public BaseResponse<String> updateStatus(Integer status,HttpServletRequest request){
        //拿到用户名
        User user = userUtils.getLoginUser(request);
        noticeBoardService.updateStatus(status,user.getUserName());
        return ResultUtils.success(status==1 ? "发布成功！" : "取消成功！");
    }


}
